package com.itheima.dao.system;

import com.itheima.domain.system.Dept;
import com.itheima.domain.system.Dept;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface DeptDao {
        @Select("select * from ss_dept")
        @Results(id="deptMap",value = {
                @Result(column = "dept_id",property = "id",jdbcType = JdbcType.VARCHAR),
                @Result(column = "dept_name",property = "deptName",jdbcType = JdbcType.VARCHAR),
                @Result(column = "parent_id",property = "parentId",jdbcType = JdbcType.VARCHAR),
                @Result(column = "state",property = "state",jdbcType = JdbcType.VARCHAR),
                @Result(column = "parent_id",property = "parent",javaType = Dept.class,one = @One(select = "com.itheima.dao.system.DeptDao.findById")),
        })
        List<Dept> findAll() throws Exception;

        @Select("select * from ss_dept where dept_id = #{depId}")
        @ResultMap("deptMap")
        Dept findById(String id)throws Exception;

        /**
         * 更新部门
         */
        @Update("update ss_dept set dept_name=#{deptName}, parent_id=#{parentId},state=#{state} where dept_id=#{id}")
        int update(Dept t);

        /**
         * 新增部门
         */
        @Insert("insert into ss_dept(dept_id,dept_name,parent_id,state) values(#{id},#{deptName},#{parentId},#{state})")
        int save(Dept t);

        /**
         * 根据ID删除部门
         */
        @Delete("delete from ss_dept where dept_id=#{deptId}")
        int deleteById(String deptId);
}
